<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet"  href="/layui/css/layui.css"/>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>产品扣款统计列表</title>
</head>
<body>
<!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="detail">删除</a> -->
<script src="/plugins/jquery/jquery-1.10.2.min.js"></script>
<script  src="/layui/layui.js"></script>
<script src="/plugins/js/common.js"></script>
<table class="layui-hide" id="productList"  lay-filter="productList"></table>
<script type="text/html" id="productListBarAction">
  <a class="layui-btn layui-btn-xs" lay-event="toDeduction">扣款</a>
   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="detail">查看详情</a>
</script>
<script type="text/javascript">
var table;
var layer;
layui.use(['table'], function(){
	layer=layui.layer;
	  table = layui.table;
	  tableIns = initTable(table);
	//监听行工具事件
	  table.on('tool(productList)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'detail'){
	    	toDetail(data.product_id);
	    } else if(obj.event === 'toDeduction'){
	    	if(data.apply_count == 0||data.apply_total_amount == 0){
	    		layer.msg('还没有用户购买该产品，无法扣款', {icon: 5});
	    	}else{
	    		toDeduction(data.product_id);
	    	}
	    }
	  });
});

function initTable(){
	table.render({
	    elem: '#productList',
	    url:'/productPay/selectStatisticsProdductPayListData',
	    cellMinWidth: 90,
	    cols:[
		    	[
			      {field:'product_name'  ,title: '产品名称'},
			      {field:'amount_protection'  ,title: '保障金额'},
			      {field:'pay_count',  title: '扣款次数'},
			      {field:'payment_total_amount',  title: '扣款总金额'},
			      {field:'apply_count',  title: '购买人数'},
			      {field:'apply_total_amount',  title: '购买总金额'},
			      {fixed: 'right', title:'操作', toolbar: '#productListBarAction'}
		    	]
	    ],page: true,
	    limit:8,
	    id: 'reloadTable'
	  });
}


	
	function search(sender){
	      //执行重载
	      table.reload('reloadTable', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	      });
	      if(!isNull(sender)){
	    	  layMsg(sender,2000);
	      }
	      return false;
	}

	function toAdd(){
		perContent = layer.open({
			         type:2,
			         title: "新增产品",
			         content: '/product/toAddProduct',
			         area: ['700px', '420px'],
			         maxmin: true,            //最大化按钮
			         anim:3,                    //动画
			         shade: [0.8, '#393D49'],//遮罩层
			         end: function(){
// 			        	 alert(1);
		            }
// 		            btn: ['提交','关闭'],
		           /* yes:function(index, layero){
		            	var iframeWin = window["layui-layer-iframe" + index];
		            	iframeWin.addUser();
		                layer.close(index);
		                search();
		            },*/
			     });
		      layer.full(perContent);
		     return false;
	}
	/**
		扣款跳转
	**/
	function toDetail(id){
		perContent = layer.open({
	         type:2,
	         title: "产品扣款详情",
	         content: '/productPay/toProductPayDetail?productId='+id,
	         area: ['700px', '420px'],
	         maxmin: true,            //最大化按钮
	         anim:3,                    //动画
	         shade: [0.8, '#393D49'],//遮罩层
	         end: function(){
           }
	     });
     layer.full(perContent);
    return false;
}
	
	/**
	扣款跳转
**/
function toDeduction(id){
	perContent = layer.open({
         type:2,
         title: "扣款操作",
         content: '/productPay/toDeduction?productId='+id,
         area: ['700px', '420px'],
         maxmin: true,            //最大化按钮
         anim:3,                    //动画
         shade: [0.8, '#393D49'],//遮罩层
         end: function(){
       }
     });
 layer.full(perContent);
return false;
}
	
</script>
<style>
.layui-table-cell{
    height:23px;
    line-height:23px;
}
</style>
</body>
</html>